<?php
/*
Template Name:Google Search Union
*/
?>
<?php get_header(); ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/cse.css" type="text/css" />
  <div id="contents" class="clearfix">

   <div id="left_col">
<?php $options = get_option('mc_options'); ?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <div class="post clearfix" id="single_post">
     <div class="post_content_wrapper">
      <h2 class="post_title"><span><?php the_title(); ?></span></h2>
      <div class="post_content">
		<?php the_content(__('Read more', 'monochrome')); ?>
		<!-- Google Custom Search Element -->
		<div id="cse" style="width: 100%;">Loading</div>
		<script src="http://www.google.cn/jsapi" type="text/javascript"></script>
		<script type="text/javascript"> 
		  function parseQueryFromUrl () {
			var queryParamName = "q";
			var search = window.location.search.substr(1);
			var parts = search.split('&');
			for (var i = 0; i < parts.length; i++) {
			  var keyvaluepair = parts[i].split('=');
			  if (decodeURIComponent(keyvaluepair[0]) == queryParamName) {
				return decodeURIComponent(keyvaluepair[1].replace(/\+/g, ' '));
			  }
			}
			return '';
		  }
		  google.load('search', '1', {language : 'zh-CN'});
		  var _gaq = _gaq || [];
		  _gaq.push(["_setAccount", "UA-18965227-1"]);
		  function _trackQuery(control, searcher, query) {
			var gaQueryParamName = "q";
			var loc = document.location;
			var url = [
			  loc.pathname,
			  loc.search,
			  loc.search ? '&' : '?',
			  gaQueryParamName == '' ? 'q' : encodeURIComponent(gaQueryParamName),
			  '=',
			  encodeURIComponent(query)
			].join('');
			_gaq.push(["_trackPageview", url]);
		  }
		  google.setOnLoadCallback(function() {
			var customSearchControl = new google.search.CustomSearchControl('partner-pub-8044246668905491:8wxhoa3j08a');
			customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
			customSearchControl.setSearchStartingCallback(null, _trackQuery);
			var options = new google.search.DrawOptions();
			options.setAutoComplete(true);
			options.enableSearchResultsOnly();     
			customSearchControl.draw('cse', options);
			var queryFromUrl = parseQueryFromUrl();
			if (queryFromUrl) {
			  customSearchControl.execute(queryFromUrl);
			}
		  }, true);
		</script>
		<link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
      </div>
     </div>
    </div>

<?php endwhile; else: ?>
    <div class="post_odd">
     <div class="post clearfix">
      <div class="post_content_wrapper">
       <?php _e("Sorry, but you are looking for something that isn't here.","monochrome"); ?>
      </div>
      <div class="post_meta">
      </div>
     </div>
    </div>
<?php endif; ?>

    <div class="content_noside">
     <?php include('navigation.php'); ?>
    </div>

   </div><!-- #left_col end -->

   <?php get_sidebar(); ?>

  </div><!-- #contents end -->

  <div id="footer">
<?php get_footer(); ?>
